package code.example.base.exception;

import code.example.tool.LogFactory;

import java.util.concurrent.TimeUnit;

/**
 *   unchecked : 不需要在方法声明上通过 throw 语法声明异常类型，方法执行时就可以（可能）抛出异常，到外层调用方法，如果外层没有捕获，就一直抛出 Thread.run ，jvm 打印出异常信息，并结束线程。
 *
 */
public class TestUnCatchRuntimeException {

    public void throwRuntimeException(){
        String str = null;
        str.length();
    }
    public static void main(String [] args){

      Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                TestUnCatchRuntimeException  testUnCatchRuntimeException =  new TestUnCatchRuntimeException();
                testUnCatchRuntimeException.throwRuntimeException();
            }
        });
        t.start();
        try {
            TimeUnit.SECONDS.sleep(5);
        }catch (Exception e){};
        Thread.State state = t.getState();
        LogFactory.getLog().info("thread state:"+state);
    }
}
